package org.dubnation.user.controller;

import org.dubnation.user.service.ILoginInfoService;
import org.dubnation.user.domain.LoginInfo;
import org.dubnation.user.query.LoginInfoQuery;
import org.dubnation.base.util.AjaxResult;
import org.dubnation.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/loginInfo")
public class LoginInfoController {
    @Autowired
    public ILoginInfoService loginInfoService;


    /**
     * 保存和修改公用的
     * @param logininfo  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult insertOrUpdate(@RequestBody LoginInfo logininfo){
        if( logininfo.getId()!=null)
            loginInfoService.update(logininfo);
        else
            loginInfoService.insert(logininfo);
        return AjaxResult.me();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        loginInfoService.delete(id);
        return AjaxResult.me();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult queryById(@PathVariable("id")Long id) {
        LoginInfo logininfo = loginInfoService.queryById(id);
        return AjaxResult.me().setData(logininfo);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult queryAll(){
        List<LoginInfo> list = loginInfoService.queryAll();
        return AjaxResult.me().setData(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult queryPage(@RequestBody LoginInfoQuery query){
        PageInfo<LoginInfo> pageInfo = loginInfoService.queryPage(query);
        return AjaxResult.me().setData(pageInfo);
    }

    /**
    * 批量删除数据
    * @param ids
    * @return
*/
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        loginInfoService.batchDelete(ids);
        return AjaxResult.me();
    }
}
